package com.android.myfilm.share.twitter;

import twitter4j.Twitter;
import twitter4j.TwitterException;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;


public class TweetsActivity extends Activity {
	
//	private TwitterListAdapter adapter;
	private final static String TAG = "TweetsActivity";

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Log.i(TAG, "Sending tweet to Twitter!");
		
		String movieTitle = getIntent().getExtras().getString("title");
		Twitter t = ((TwitterApplication)getApplication()).getTwitter();
		
		try {
			t.updateStatus("I'm watching " + movieTitle + ", right now!");
			Toast.makeText(this, "Twitter status updated!", Toast.LENGTH_LONG).show();
			Log.i(TAG, "Finishing TweetsActivity");
			finish();
		} catch (TwitterException e) {
			if (e.getStatusCode() == 403) {
				Toast.makeText(this, "Status already updated!", Toast.LENGTH_LONG).show();
				e.printStackTrace();
				finish();
			}
			else {
				Toast.makeText(this, "Something went wrong, sorry!", Toast.LENGTH_LONG).show();
				e.printStackTrace();
				finish();
			}
		}
		
//		ArrayList<JSONObject> jobs = TweetReader.retrieveSpecificUsersTweets(t);
		
//		adapter = new TwitterListAdapter(this,jobs);
//		setListAdapter(adapter);
	}

}